import { SetMetadata } from "@nestjs/common";
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
import { ApiBearerAuth } from "@nestjs/swagger";
import { Request } from "express";


export const  RequireLogin = () => SetMetadata('login', true);

export const  RequirePermission = (...permissions: string[]) => SetMetadata('permission', permissions);

//自定义参数装饰器
export const UserInfo = createParamDecorator(
  (data: string, ctx: ExecutionContext) => {
    const request = ctx.switchToHttp().getRequest<Request>();
    if(!request.user) {
        return null;
    }
    return data ? request.user[data] : request.user;
  },
)
